package com.cdtu.store.item.controller;

import com.cdtu.store.common.utils.PageUtils;
import com.cdtu.store.common.utils.R;
import com.cdtu.store.common.entity.StockEntity;
import com.cdtu.store.item.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 库存表，代表库存，秒杀库存等信息
 *
 * @author dongyuhao
 * @email a1059444570@qq.com
 * @date 2020-06-22 19:53:25
 */
@RestController
@RequestMapping("stock")
public class StockController {
    @Autowired
    private StockService stockService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = stockService.list(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    public R info(@PathVariable("skuId") Long skuId){
		StockEntity stock = stockService.getById(skuId);

        return R.ok().put("stock", stock);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody StockEntity stock){
		stockService.save(stock);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody StockEntity stock){
		stockService.updateById(stock);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] skuIds){
		stockService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
